#include <vector>

using namespace std;

class Solution {
public:
    int maxProfit(vector<int>& prices) {
        if (prices.size() == 0) {
            return 0;
        }
        int buy = -prices[0];
        int sell = 0;
        int cool = 0;
        for (int i = 1; i < prices.size(); i++) {
            int _buy = max(cool - prices[i], buy);
            int _sell = max(buy + prices[i], sell);
            int _cool = max(sell, cool);
            buy = _buy;
            sell = _sell;
            cool = _cool;
        }
        return sell;
    }
};
